﻿
using Maticsoft.BLL;
using Maticsoft.Model;

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_Youhui_YiGou : SystemBBasePage
{

    public Maticsoft.BLL.Coupon coup = new Maticsoft.BLL.Coupon();
    public Maticsoft.Model.Coupon coupmodel = new Maticsoft.Model.Coupon();


    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.getYiGou();
    }

    private void getYiGou()
    {
        int num;
        StringBuilder builder = new StringBuilder();
        builder.Append("<tr>");
        builder.Append("<th width='100'>编号</th>");
        builder.Append("<th width='440'>项目</th>");
        builder.Append("<th width='180'>用户</th>");
        builder.Append("<th width='140'>过期日期</th>");
        builder.Append("</tr>");
        StringBuilder builder2 = new StringBuilder();
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        Maticsoft.BLL.Team team = new Maticsoft.BLL.Team();
        List<Maticsoft.Model.Coupon> list = new List<Maticsoft.Model.Coupon>();
        list = this.coup.SearchCoupon(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, "*", "order by Id desc", this.sqlWhere, out num);
        this.AspNetPager1.RecordCount = num;
        this.pages = this.AspNetPager1.CurrentPageIndex;
        int num2 = 0;
        foreach (Maticsoft.Model.Coupon coupon in list)
        {
            if ((num2 % 2) != 0)
            {
                builder2.Append("<tr>");
            }
            else
            {
                builder2.Append("<tr class='alt'>");
            }
            num2++;
            builder2.Append("<td>" + coupon.Id + "</td>");
            if (team.GetModelList("Id=" + coupon.Team_id).Count > 0)
            {
                foreach (Maticsoft.Model.Team team2 in team.GetModelList("Id=" + coupon.Team_id))
                {
                    builder2.Append(string.Concat(new object[] { "<td>", team2.Id, "&nbsp;(<a class='deal-title' href='/team.aspx?id=ZTNA==' target='_blank'>", team2.Title, "</a>)</td>" }));
                }
            }
            else
            {
                builder2.Append("<td>(&nbsp;)</td>");
            }
            if (info.GetModelList("Id=" + coupon.User_id).Count > 0)
            {
                foreach (Maticsoft.Model.UserInfo info2 in info.GetModelList("Id=" + coupon.User_id))
                {
                    builder2.Append("<td nowrap>" + info2.Email + "<br/>" + info2.Username + "</td>");
                }
            }
            else
            {
                builder2.Append("<td nowrap>(暂无用户)</td>");
            }
            builder2.Append("<td nowrap>" + coupon.Expire_time + "</td>");
            builder2.Append("</tr>");
        }
        this.Literal1.Text = builder.ToString();
        this.Literal2.Text = builder2.ToString();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "youhuiquan";
        if (!this.Page.IsPostBack)
        {
            this.getYiGou();
        }
        if (base.Request["btnselect"] == "筛选")
        {
            this.Search();
        }
    }

    public void Search()
    {
        string text = this.txtteamid.Text;
        string str2 = this.txtcouponid.Text;
        if ((text != "") && (str2 == ""))
        {
            this.sqlWhere = " Expire_time<GetDate() and Team_id=" + Convert.ToInt32(text);
        }
        else if ((text == "") && (str2 != ""))
        {
            this.sqlWhere = " Expire_time<GetDate() and Id='" + str2 + "'";
        }
        else if ((text != "") && (str2 != ""))
        {
            this.sqlWhere = string.Concat(new object[] { " Expire_time<GetDate() and Id='", str2, "' and Team_id=", Convert.ToInt32(text) });
        }
        else
        {
            this.sqlWhere = " Expire_time<GetDate() ";
        }
        this.getYiGou();
    }

    public int pages
    {
        get
        {
            if (this.ViewState["pages"] != null)
            {
                return Convert.ToInt32(this.ViewState["pages"].ToString());
            }
            return 1;
        }
        set
        {
            this.ViewState["pages"] = value;
        }
    }

    public string sqlWhere
    {
        get
        {
            if (this.ViewState["sqlWhere"] != null)
            {
                return this.ViewState["sqlWhere"].ToString();
            }
            return " Expire_time<GetDate()";
        }
        set
        {
            this.ViewState["sqlWhere"] = value;
        }
    }
}

